package gsp420.game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

// is this really needed with both the player and enemy implemented the way they are?
public class Entity {
	/** icon, drawn if it exists */
	private Image img;
	/** background to draw under the icon */
	public Color color;
	/** col/row of the player. */
	public byte x, y;
	public Entity(){}
	/**
	 * @param img {@link #img}
	 * @param color {@link #color}
	 * @param x {@link #x}
	 * @param y {@link #y}
	 */
	public void init(Image img, Color color, int x, int y){
		this.img = img;
		this.color = color;
		this.x = (byte)x;
		this.y = (byte)y;
	}
	void drawAtPixelLoc(Graphics g, int a_x, int a_y, int a_sqW, int a_sqH)
	{
		g.setColor(color);
		g.fillRect(a_x, a_y, a_sqW, a_sqH);
		g.drawImage(img, a_x, a_y, null);
	}
	/**
	 * puts upper-left corner of  {@link #img} (if not null) at the given offset
	 * @param g which context to draw in
	 * @param a_offsetX pixel offset to start drawing at, taking the entity's x/y into account
	 * @param a_offsetY
	 * @param a_sqW size (in pixels) to draw the background color
	 * @param a_sqH
	 */
	void draw(Graphics g, int a_offsetX, int a_offsetY, int a_sqW, int a_sqH)
	{
		int dx = a_offsetX+x*a_sqW;
		int dy = a_offsetY+y*a_sqH;
		drawAtPixelLoc(g, dx, dy, a_sqW, a_sqH);
	}
}
